package com.bwf.service;

import com.bwf.exception.DepositException;
import com.bwf.pojo.Account;

import java.util.Scanner;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2022/12/19 13:36
 * @copyright: 博为峰
 */
public class ATM {
    public Scanner scanner;
    public Bank bank;

    public ATM() {
        scanner = new Scanner(System.in);
        bank = new Bank();
    }

    public void service() {
        System.out.println("请输入卡号");
        String cardNo = scanner.nextLine();
        System.out.println("请输入密码");
        String password = scanner.nextLine();
        //校验
        Account account = bank.verify(cardNo, password);
        if (account != null) {
            do {
                System.out.println("1.存钱2.取钱3.查看");
                String s = scanner.nextLine();
                switch (s) {
                    case "1":
                        System.out.println("请输入存款金额");
                        String money = scanner.nextLine();
                        double my = Double.parseDouble(money);
                        account.save(my);
                        break;
                    case "2":
                        System.out.println("请输入取款金额");
                        String dmoney = scanner.nextLine();
                        double dmy = Double.parseDouble(dmoney);
                        //取钱
                        try {
                            account.deposit(dmy);
                        } catch (DepositException e) {
                            System.out.println("余额不足，好好学习，努力工作");
                        }
                        break;
                    case "3":
                        System.out.println(account.getBalance());
                        break;
                    default:
                }
            } while (true);
        }
    }
}
